package com.salton123.groupbargain.ui

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.AppUtils
import com.lxj.xpopup.XPopup
import com.qw.soul.permission.SoulPermission
import com.salton123.feature.PermissionFeature


/**
 * User: newSalton@outlook.com
 * Date: 2019/8/6 17:46
 * ModifyTime: 17:46
 * Description:
 */
class SplashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        object : PermissionFeature() {
            override fun onRequestFinish(isGranted: Boolean) {
                super.onRequestFinish(isGranted)
                if (isGranted) {
                    val intent = Intent(this@SplashActivity, MainActivity::class.java)
                    intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
                    startActivity(intent)
                    finish()
                } else {
                    XPopup.Builder(this@SplashActivity)
                        .dismissOnTouchOutside(false)
                        .dismissOnBackPressed(false)
                        .asConfirm("提示", "权限不足,请允许应用获取权限", {
                            SoulPermission.getInstance().goApplicationSettings {}
                        }, {
                            AppUtils.exitApp()
                        })
                        .show()
                }

            }
        }.onBind()

    }

    override fun onBackPressed() {

    }
}
